package handler

import (
	"cargo-link/model"
	"github.com/gin-gonic/gin"
	"strconv"
)

func CarAdd(c *gin.Context) {
	CarCode := c.PostForm("CarCode")
	CarName := c.PostForm("CarName")
	data := model.Car{
		CarCode: CarCode,
		CarName: CarName,
	}
	err := model.DB.Debug().Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}

func LinkAdd(c *gin.Context) {
	LinkCode := c.PostForm("LinkCode")
	LinkName := c.PostForm("LinkName")
	Cid, _ := strconv.Atoi(c.PostForm("Cid"))
	data := model.Link{
		LinkCode: LinkCode,
		LinkName: LinkName,
		Cid:      Cid,
	}
	err := model.DB.Debug().Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
